package cn.javaweb.group0.servlet;

import cn.javaweb.group0.entity.Module;
import cn.javaweb.group0.model.ModuleModel;
import cn.javaweb.library.AjaxResult;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

@WebServlet("/module/list")
public class ModuleListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int pageNum = Integer.parseInt(req.getParameter("page"));
        int pageLimit = Integer.parseInt(req.getParameter("limit"));

        ModuleModel moduleModel = new ModuleModel();

        int total = moduleModel.getTotal();
        List<Module> rows = moduleModel.getModuleList( pageNum, pageLimit);

        HashMap<String, Object> result = new HashMap<String, Object>();

        result.put("total", total);
        result.put("rows", rows);

        resp.getWriter().print(AjaxResult.success("操作成功", result ));
    }

}
